import express from 'express';
import { Request, Response } from 'express';
import { userType, userService } from '../../services/user-service';
import { getResult, getErr } from '../getSendResult'
import jwt from '../jwt';
const router = express.Router();
//获取所有用户
router.get('/', (req: Request, res: Response) => {
  console.log(req.path);
})
//获取一个用户
router.get('/info', async (req: Request, res: Response) => {
  const userInfo: any = jwt.verify(req);
  const result: object = await userService.getUserInfo(userInfo.userId);
  res.send(getResult(result))
})
// 添加一个用户
router.post("/", async (req: Request, res: Response) => {
  const result = await userService.getAllUser();
  res.send(getResult(result))
});
// 添加一个管理员
router.post("/admin", async (req: Request, res: Response) => {
  const result = await userService.addAdmin(req.body?.loginId, req.body.loginPwd);
  res.send(getResult(result))
});

export default router